﻿using Microsoft.AspNetCore.Mvc;
using mvc6._0.Models;
using mvc6.Services;

namespace mvc6.Controllers
{

    /// <summary>
    /// 添加完这个控制器之后，就可以直接访问了。
    /// 访问的地址是 /First
    /// 控制器中方法的访问/First/Index
    /// </summary>
    public class FirstController : Controller
    {

        private readonly ILogger<FirstController> _logger;
        private readonly IMyService _myService;

        public FirstController(ILogger<FirstController> logger,IMyService myService)
        {
            this._logger = logger;

            this._logger.LogInformation($"{this.GetType().Name} 被构造了。。。");

            this._myService = myService;
        }




        /// <summary>
        /// 请求方法 /First/Index
        /// </summary>
        /// <returns></returns>
        public IActionResult Index()
        {



            // 将计算的结果传到页面上去的方法
            ViewBag.User1 = "yejing";
            ViewData["user2"] = "王大毛";
            TempData["user3"] = "王五";
            HttpContext.Session.SetString("user4", "马六");
            
            _logger.Log(logLevel: LogLevel.Information,"index");

            // 返回视图
            return View();
        }

        public IActionResult Login(User user)
        {

            User user1 = new User()
            {
                Name = user.Name,
                Age = user.Age
            
            };


            return View(user1);
        }


        public IActionResult Logout()
        {
            ViewData["msg"] = "登出";

            return View();
        }

        public IActionResult SayHi() 
        {

            ViewData["msg"] = _myService.SayHi("yejing");

            return View();
        }
    }
}
